package com.social.controller;

import com.social.dao.UserDao;
import com.social.pojo.Result;
import com.social.pojo.SysUser;
import com.social.service.SysUserService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;


/**
 * @BelongsProject: social
 * @BelongsPackage: com.social.controller
 * @Author: zhm
 * @CreateTime: 2022-09-26  21:20
 * @Description: TODO
 * @Version: 1.0
 */

@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserDao userDao;

    @Autowired
    private SysUserService sysUserService;

    /**
     * 发送验证码
     * @param
     * @return
     */
    @ApiOperation("发送验证码")
    @PostMapping("/code")
    public Result sendCode(@RequestParam("phone") String phone, HttpSession session) {
        // 发送短信验证码并保存验证码
        return sysUserService.sendCode(phone, session);
    }

    @ApiOperation("用户注册")
    @GetMapping("/register")
    public Result register(SysUser sysUser, HttpSession session) {
        return sysUserService.register(sysUser, session);
    }

    @ApiOperation("用户登录")
    @RequestMapping("/login")
    public Result login(SysUser userlogin, HttpSession httpSession) {
        return sysUserService.login(userlogin, httpSession);
    }
}
